<script>
  jQuery(document).ready(function(){
    create_scrollable('#week_list', 20, '#week_<?= $this->current_week ?>', 'Week');
  });
</script>

<div id="tabs" style="padding-top:10px;">
  <ul id="week_list">
<?  if(!empty($this->weeks)):
      foreach(array_keys($this->weeks) as $index): ?>
      <li id="week_<?= $index ?>">
        <a href="<?= JRoute::_('index.php?option=com_pbny&controller=schedules&task=display&id='.$index) ?>" ><?= ($index+1) ?></a>
      </li>
<?    endforeach;
    endif;
?>

  </ul>
</div>

<table id="division_symbols" width="100%" style="margin:1em;">
  <?$count = 1;
    foreach($this->divisions as $division): 
  ?>
    <? if($count > 3) $count =1; ?>
	<? if($count == 1): ?>
         <tr width="100%">
    <? endif; ?>
	
       <td width="33%" align="center">
	     <h3 style="margin:10px 110px 0px 0px;color:<?= $division->color?>"><?= JText::_(strtoupper($division->name)) ?></h3>
	   </td>
	   
    <? if($count == 3 ): ?><td></td>
	     </tr>
    <? endif;
	   $count++;
	?>
  
  <? endforeach;?>
</table>

<table width="100%" style="margin:1em;">
<? $count = 1; ?>
<? if(!empty($this->schedules)):
    foreach($this->schedules as $schedule): 
    $first_team_name  = $schedule->first_team->abbr;
    $second_team_name = $schedule->second_team->abbr;
    
    if(empty($first_team_name))
      $first_team_name  = $schedule->first_team->name;
    if(empty($second_team_name))
      $second_team_name = $schedule->second_team->name;
    
	$game_end_status = null;
	if(isset($schedule->game_end_status))
	  $game_end_status = $schedule->game_end_status->code;
?>
  
  <? if($count > 3) $count = 1; ?>
  <? if($count == 1): ?>
    <tr style="padding-bottom:.5em;" valign="top">
  <? endif; ?>
    <td style="width:30%; text-align:center;">
      <table class="schedule" border="0" cellpadding="0" cellspacing="0">
        <? $bg_color = null; 
           if(isset($schedule->division)):
             $bg_color = $schedule->division->color;
        ?>
          <tr>
            <td colspan="3" style="height:3px">
              <div style="height:100%;background-color:<?= $bg_color ?>"></div>
            </td>
          </tr>
        <? endif; ?>
        <tr>
          <td class="team"><h3><?= $first_team_name ?></h3></td>
          <td valign="bottom"><h3><?= $game_end_status ?></h3></td>
          <td class="team"><h3><?= $second_team_name ?></h3></td>
        </tr>
        <tr>
          <td class="score" style="border-left:none;"><h2 style="color:#ccc"><?= $schedule->final_score[$schedule->first_team->id] ?></h2></td>
          <td valign="bottom">
            <div style="width:100%; line-height:20px; background-color:#222;color:#ccc;font-weight:bold;">
              <?= strtoupper(strftime('%b %d %I:%M %p', strtotime($schedule->schedule))) ?>
            </div>
          </td>
          <td class="score" style="border-right:none;"><h2 style="color:#ccc"><?= $schedule->final_score[$schedule->second_team->id] ?></h2></td>
        </tr>
        <tr>
          <td colspan="3"><?= $schedule->venue->name ?></td>
        </tr>
      </table>
      <a href="<?= JRoute::_('index.php?option=com_pbny&controller=schedules&task=display_schedule&id='.$schedule->id)?>" style="color:#ccc;">View Stats</a>
    </td>
  <? if($count == 3): ?>
    </tr>
  <? endif; ?>    
  <? $count++ ?>
<?  endforeach; 
  endif; ?>

<? if($count == 1 && !empty($this->bye_teams)): ?>
  <tr>
<? endif; ?>

  <td style="width:30%; text-align:center;">
    <table class="schedule bye" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td colspan="3" class="team" style="background-color:#ccc"><h3>BYE</h3></td>
      </tr>
      <? if(!empty($this->bye_teams)):
	       $count = 1; 
	       foreach($this->bye_teams as $bt): ?>
	         <? if($count > 3) $count = 1; ?>
	         <? if($count == 1): ?>
               <tr>
	         <? endif; ?>
	  
             <td valign="bottom" class="bye">
               <h3><?= $bt->abbr; ?></h3>
             </td>
		
  	         <? if($count == 3): ?>
               </tr>
	         <? endif; 
	         $count++; ?>
           <? endforeach;
         endif; ?>
    </table>
  </td>

  
<? if($count == 1 && !empty($this->bye_teams)): ?>
  </tr>
<? endif; ?>
  
</table>

